<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
//公众号操作员设置。管理公众号操作员，对操作员进行增删查改。
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
exi('','','core/basic.plugin_perm//plugin_name=jy_weishop');
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$return['list']=pdo_getall('jy_weishop_perms',$params,array('id','uniacid','operator'));
	foreach($return['list'] as &$v){
		$v['name']=pdo_getcolumn('core_users',array('id'=>$v['operator']),'name');
	}
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'操作员列表'),
			array('op'=>'edit','title'=>'添加操作员'),
		),
		'list'=>array('data'=>'list','html_to'=>'list_html','list'=>array(
			array('name'=>'operator','title'=>'操作员ID','type'=>'string'),
			array('name'=>'name','title'=>'操作员名称','type'=>'string'),
		)),
	
	);
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='edit'){
	$uid=intval($_RQ['id']);
	if($uid){
		$item=pdo_get('jy_weishop_perms',array('id'=>$uid,'uniacid'=>$_SESSION['uniacid']),array('id','uniacid','operator','perm1','perm2'));
	}else{
		$item=array();
	}
	$return['item']=$item;
	$return['user']=pdo_getall('core_users',array('uniacid'=>$_SESSION['uniacid'],'type'=>array('1','2','4')),array('id','name'),'id');
	$menu=$this->menu();
	foreach($menu as $v){
		$k=$v['url'];
		$return['perm1'][$k]=$v['title'];
		foreach($v['child'] as $c){
			foreach($c['child'] as $x){
			$e=$x['url'];
			$return['perm2'][$e]=$x['title'];
		}
		}
	}
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'权限管理',
		'tabs'=>array(
			'0'=>array('op'=>'list','title'=>'操作员列表'),
			'1'=>array('op'=>'edit','title'=>'添加操作员'),
		),
		'edit'=>array(
			array('type'=>'select','title'=>'选择操作员','name'=>'operator','options'=>'user','option_title'=>'name', 'help'=>'请先在站点设置里添加好对应操作员并赋予“商城”插件权限' ),			
			array('type'=>'checkbox','title'=>'主菜单设置','name'=>'perm1','options'=>'perm1','help'=>'设置主菜单权限'),
			array('type'=>'checkbox','title'=>'子菜单设置','name'=>'perm2','options'=>'perm2','help'=>'设置子菜单权限' ),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array_fields(array('operator','perm1','perm2'),$postdata);
	
	$id=intval($postdata['id']);
	
	
	if($id){
		pdo_update('jy_weishop_perms',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		$message='修改成功！';
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_weishop_perms',$data);
		$id=pdo_insertid();
		$message='添加成功！';
	}
	
	exi($message,'','list');
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_weishop_perms',array('id'=>$id));
		
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_weishop_perms',array('id'=>$id));
				
			}
		}
	}
	exi('删除成功！');
}
?>